//
//  Extension+UIBarButtonItem.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/19.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    convenience init(title: String? = nil,imgName: String? = nil,target: AnyObject?,action: Selector) {
        self.init()
        
        let button = UIButton()
        
        if let tit = title {
            button.setTitle(tit, forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(15)
            button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Disabled)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        }
        
        if let img = imgName {
            
            button.setBackgroundImage(UIImage(named: img), forState: UIControlState.Normal)
        }
        
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        button.sizeToFit()
        self.customView = button
    }

}
